using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RpgXna.Model.SpriteBase;

namespace RpgXna.Model.Entities
{
    public class Tree : CollidableSprite, IEnvironment
    {
        private readonly Vector2 _canopeePosition;
        private readonly string _canopeeResName;

        private readonly int _id;
        private readonly string _trunkResName;
        private Texture2D _canopee;
        private Vector2 _canopeeorigin;

        public Tree(int id, int x, int y, string trunkResName, string canopeeResName)
        {
            _id = id;
            _trunkResName = trunkResName;
            _canopeeResName = canopeeResName;
            _canopeePosition = new Vector2(x, y);
            Position = new Vector2(x, y);
            Rotation = 0f;
            Direction = Vector2.Zero;
            Speed = Vector2.Zero;
        }

        #region IEnvironment Members

        public int Id
        {
            get { return _id; }
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(Texture, Position, null, Color.White, Rotation, Origin, Scale, SpriteEffects.None, 0);
            sb.Draw(_canopee, _canopeePosition, null, Color.White, Rotation, _canopeeorigin, Scale, SpriteEffects.None, 0);
        }

        public void Load(ContentManager cm)
        {
            LoadTexture(cm.Load<Texture2D>(_trunkResName));
            _canopee = cm.Load<Texture2D>(_canopeeResName);
            _canopeeorigin = new Vector2((float)_canopee.Width / 2, (float)_canopee.Height / 2);
        }

        public void Update()
        {
        }

        #endregion IEnvironment Members
    }
}